package cn.aiweiyi.qingjing.coupon.distribution.controller;

import cn.aiweiyi.qingjing.coupon.comm.annotation.IgnoreResponseAdice;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @author 青衿
 * @Date 2020/11/23 15:51
 * Ribbon测试控制器
 **/
@Slf4j
@RestController
public class RibbonController {
    @Autowired
    private RestTemplate restTemplate;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    private static class TemplateInfo {
        private Integer code;
        private String message;
        private List<Map<String, Object>> data;
    }

    /**
     * 通过Ribbon调用模板微服务的方法,该处理器URL为:/coupon-distribution/info
     *
     * @return
     */
    @GetMapping("/info")
    @IgnoreResponseAdice//忽略统一响应,因为template模块的控制器已经封装过了
    public Object getTemplateInfo() {
        String infoUrl = "http://eureka-client-coupon-template/coupon" +
                "-template/info";
        return restTemplate.getForEntity(infoUrl, TemplateInfo.class)
                .getBody();
    }

}
